package arithmetic.baseAlgorithm.sort;

/**
 * 选择排序
 * <p>
 * 时间复杂度:n^2
 * 依次计算出每个位置最小的值
 *
 * @author zhangyanqi
 * @since 1.0 2017/10/18
 */
public class SelectionSort {

    public static void sort(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            int a = nums[i];
            for (int j = i; j < nums.length; j++) {
                if (nums[j] < a) {
                    nums[i] = nums[j];
                    nums[j] = a;
                    a = nums[i];
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] ints = {3, 2, 1};
        sort(ints);
        System.out.println(ints[0] + " " + ints[1] + " " + ints[2]);
    }
}
